﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Storage
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            ItemAcceptance IA = new ItemAcceptance();
            IA.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            MySQLDriver drv = MySQLDriver.GetDriver;
            string cmd = "Select * from Users where login = '" + loginBox.Text + "' and password = '" + passBox.Text + "'";
            MySqlDataReader MyDataReader = drv.Read(cmd);
            while (MyDataReader.Read())
            {
                if ((MyDataReader.GetString(1) == loginBox.Text) && (MyDataReader.GetString(2) == passBox.Text))
                {
                    if (MyDataReader.GetInt32("dba")!=0) 
                    {
                        dbaBtn.Enabled = true;
                    }
                    if (MyDataReader.GetInt32("bill_manager") != 0)
                    {
                        billBtn.Enabled = true;
                    }
                    if (MyDataReader.GetInt32("order_manager") != 0)
                    {
                        orderBtn.Enabled = true;
                    }
                    if (MyDataReader.GetInt32("item_loader") != 0)
                    {
                        AcceptBtn.Enabled = true;
                    }
                                
                        statusIndicator.Text = "Вы зашли как " + MyDataReader.GetString(1);
                        statusIndicator.ForeColor = System.Drawing.Color.Green;
                        loginLbl.Visible = false;
                        passLbl.Visible = false;
                        loginBox.Visible = false;
                        passBox.Visible = false;
                        enterBtn.Visible = false;
                        ExitBtn.Visible = true;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            BillMode bm = new BillMode();
            bm.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OrderMode om = new OrderMode();
            om.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DBAFrom DBA = new DBAFrom();
            DBA.Show();
        }

        private void ExitBtn_Click(object sender, EventArgs e)
        {
                        dbaBtn.Enabled = false;
                        billBtn.Enabled = false;
                        orderBtn.Enabled = false;
                        AcceptBtn.Enabled = false;
                        statusIndicator.Text = "Вы не вошли ";
                        statusIndicator.ForeColor = System.Drawing.Color.Red;
                        loginLbl.Visible = true;
                        passLbl.Visible = true;
                        loginBox.Visible = true;
                        passBox.Visible = true;
                        enterBtn.Visible = true;
                        ExitBtn.Visible = false;            
        }
    }
}
